{extend name="Master/base" /} {block name="title"}后台主页{/block} {block name="main"}
<section class="content-header">
    <h1>
        分配权限
    </h1>
</section>

<section class="content">
    <div class="row">
        <div class="box box-success">
            <div class="box-header with-border">
                <h3 class="box-title">{$role.name} - 分配权限</h3>
                <div class="box-tools">
                    <div class="input-group input-group-sm" style="width: 550px;">
                        <a href="javascript:;" class="btn label-info pull-right " style="width: 100px; margin-left: 10px" id="save_menu">保存权限</a>
                        <a href="{:url('/index/user/role')}" class="btn label-default pull-right" style="width: 100px;">返回</a>
                        <div class="input-group input-group-sm pull-right" style="width: 150px; margin-right: 10px">

                            <input type="text" name="table_search" class="form-control pull-right" placeholder="搜索">
                            <div class="input-group-btn">
                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>


            <div class="box-body table-responsive no-padding">
                <form action="{:url('save')}" id="save_menu_form">
                    <input type="hidden" name="role_id" id="role_id" value="{$role_id}">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th style="width: 60px"><input type="checkbox" class="select_all">全选</th>
                                <th>名称</th>
                                <th>地址</th>
                                <th>类型</th>
                                <th>级别</th>
                            </tr>
                            <tbody class="table_data">
                                {volist name="menu_tree" id="vo" key="key"}
                                <tr>
                                    <td><input type="checkbox" value="{$vo.id}" name="menu_ids[]" {:in_array($vo.id,$menu_ids)? 'checked="checked"': ''}>{$key}</td>
                                    <td>| {$vo.title}</td>
                                    <td>{$vo.url}</td>
                                    <td>{$menu_type[$vo.type]}</td>
                                    <th>{$vo.level}</th>
                                </tr>
                                {/volist}
                            </tbody>
                        </thead>
                    </table>
                </form>
            </div>
        </div>
    </div>
</section>
{/block}
<!--script-->
{block name="script"}
<script>
    $(".select_all").click(function() {
        $(":checkbox", $(".table_data")).prop("checked", $(this).prop("checked"));
    });
    $("#save_menu").click(function() {
        var len = $('input[type=checkbox]:checked', $(".table_data")).length;
        if (len <= 0) {
            bootoast({
                message: "请选择",
                type: 'danger',
                position: 'right-top',
                timeout: 2
            });
            return false;
        }
        $.post("{:url('save')}", $("#save_menu_form").serialize(), function(data) {
            console.log(data);
            if (data.code == 1) {
                bootoast({
                    message: data.msg,
                    type: 'success',
                    position: 'right-top',
                    timeout: 2
                });
                setTimeout(function() {
                    window.location.reload();
                }, 1500);
            } else {
                bootoast({
                    message: data.msg,
                    type: 'danger',
                    position: 'right-top',
                    timeout: 2
                });
            }
        })

    });
</script>
{/block}